<?php
namespace App\Wen\Utils;

use App\Lib\Classes\AcAutomation;

class SafeUtils{

    private static $sql_keyword_actree = null;

    private static function get_sql_keyword_actree(){
        if(self::$sql_keyword_actree){
            return self::$sql_keyword_actree;
        }
        $sql_keyword = 'add,all,alter,analyze,and,as,asc,asensitive,before,between,bigint,binary,blob,both,by,call,cascade,case,change,char,character,check,collate,column,condition,connection,constraint,continue,convert,create,cross,current_date,current_time,current_timestamp,current_user,cursor,database,databases,day_hour,day_microsecond,day_minute,day_second,dec,decimal,declare,default,delayed,delete,desc,describe,deterministic,distinct,distinctrow,p,double,drop,dual,each,else,elseif,enclosed,escaped,exists,exit,explain,false,fetch,float,float4,float8,for,force,foreign,from,fulltext,goto,grant,group,having,high_priority,hour_microsecond,hour_minute,hour_second,if,ignore,in,index,infile,inner,inout,insensitive,insert,int,int1,int2,int3,int4,int8,integer,interval,into,is,iterate,join,key,keys,kill,label,leading,leave,left,like,limit,linear,lines,load,localtime,localtimestamp,lock,long,longblob,longtext,loop,low_priority,match,mediumblob,mediumint,mediumtext,middleint,minute_microsecond,minute_second,mod,modifies,natural,not,no_write_to_binlog,null,numeric,on,optimize,option,optionally,or,order,out,outer,outfile,precision,primary,procedure,purge,raid0,range,read,reads,real,references,regexp,release,rename,repeat,replace,require,restrict,return,revoke,right,rlike,schema,schemas,second_microsecond,select,sensitive,separator,set,show,smallint,spatial,specific,sql,sqlexception,sqlstate,sqlwarning,sql_big_result,sql_calc_found_rows,sql_small_result,ssl,starting,straight_join,table,terminated,then,tinyblob,tinyint,tinytext,to,trailing,trigger,true,undo,union,unique,unlock,unsigned,update,usage,use,using,utc_date,utc_time,utc_timestamp,values,varbinary,varchar,varcharacter,varying,when,where,while,with,write,x509,xor,year_month,zerofill';
        self::$sql_keyword_actree = new AcAutomation(explode(',',' '.$sql_keyword. ' '));
        return self::$sql_keyword_actree;
    }


    /** todo 修复
     * @param $string
     * @return bool
     */
    public static function is_sql_injection($string){
        if(_empty_($string)){
            return false;
        }
        return false;
        $results = self::get_sql_keyword_actree()->search($string);
        if($results && count($results) >= 3){
            return true;
        }
        return false;
    }


    public static function mini_common_rsa_encrypt($str){
        $public_key = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAodQjLQNkbvyETqCyRcmWg2+sR4Rfhd4IY1mbHJmmnEM9KsKkJePZhU3xd9l3QeI6nz9Fvo4UFRGUcSbB1hAaMQXGFnqN/IDkO/mn93nFtrAqWrlGRHkILxazn0r0eIuxn9wq5Coz5FcgCTVvU3pgwDfAoUm580/F17XLr7oWaFTAqtZNZgCwSD+pJzmDYNuV6VTgCFvO84A4Wbi+pE5Qk/iOpoXnsgbYMgIH83n/uROohxJ/SENUA9vnMW9jqQdyAVxPgNOUI2X0dYiY3cxr46b9VhAdPOH5A2wRJAD0y8vZlOllJM/kHrq4YXe/Gf1tQxUZVMpvaT7wmOtEwdMS8QIDAQAB';
        openssl_public_encrypt($str, $stred, "-----BEGIN PUBLIC KEY-----\n" . wordwrap($public_key, 64, "\n", true) . "\n-----END PUBLIC KEY-----");
        return $stred;
    }

}
